package com.woniu.smart.controller;

import com.github.pagehelper.PageInfo;
import com.woniu.smart.dto.OperationDTO;
import com.woniu.smart.entity.Operation;
import com.woniu.smart.entity.RepairType;
import com.woniu.smart.service.OperationService;
import com.woniu.smart.util.Result;
import com.woniu.smart.vo.OperationVO;
import com.woniu.smart.vo.WarningVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program: smart
 * @description:
 * @author: qqq
 * @create: 2022-10-23 14:31
 **/
@RestController
@RequestMapping("operations")
public class OperationController {
    @Autowired
    private OperationService operationService;
    @PostMapping("queryAll")
    public Result queryAll(@RequestBody OperationDTO operationDTO){
        List<OperationVO> operationVOS = operationService.selectAll(operationDTO);
        PageInfo<OperationVO> operationVOPageInfo = new PageInfo<>(operationVOS);
        return Result.ok().data("operationList",operationVOPageInfo);
    }
    @GetMapping("retypes")
    public Result queryAllType(){
        List<RepairType> repairTypes = operationService.selectAll();
        return Result.ok().data("repairTypes",repairTypes);
    }
    @GetMapping("{id}")
    public Result queryById(@PathVariable("id") Long id){
        OperationVO operation = operationService.selectByPrimaryKey(id);
        return Result.ok().data("operation",operation);
    }
    @PostMapping()
    public Result add(@RequestBody WarningVO operation){
        int i = operationService.insertSelective(operation);
        return Result.ok();
    }
    @PostMapping("dispose")
    public Result dispose(@RequestBody OperationVO operationVO){
        int i = operationService.dispose(operationVO);
        return Result.ok();
    }

    @DeleteMapping("{id}")
    public Result delete(@PathVariable("id") Long id){
        int i = operationService.deleteByPrimaryKey(id);
        return Result.ok();
    }
}
